package threadLocalTest;

import java.util.concurrent.TimeUnit;

/**
 * 通过threadlocal ,记录程序执行时间
 *
 * @author: luolidong
 * @create: 2021-07-11 17:31
 * @version: 1.0
 */
public class Profiler {
    private static final ThreadLocal<Long> TIME_THREAD_LOCAL=new ThreadLocal<Long>(){
        @Override
        protected Long initialValue() {
            return System.currentTimeMillis();
        }
    };

    public static void start(){
        TIME_THREAD_LOCAL.set(System.currentTimeMillis());
    }

    public static Long end(){
        return System.currentTimeMillis()-TIME_THREAD_LOCAL.get();
    }

    public static void main(String[] args) throws InterruptedException {
//        Profiler.start();
//        TimeUnit.SECONDS.sleep(1);
//        Test1.play();
    }
}
